{extend name="official/layout" /}

{block name="style"}
<link rel="stylesheet" href="/assets/css/contributions.css">
{/block}

{block name="content"}
<!-- 页面头部 -->
<section class="contributions-hero">
    <div class="container text-center">
        <h1><i class="bi bi-file-earmark-text"></i> 我的投稿</h1>
        <p>查看和管理您的投稿内容</p>
    </div>
</section>

<div class="container my-5">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div class="filter-tabs">
            <a href="/contributions.html" class="filter-tab {if condition='!isset($status) || $status eq ""'}active{/if}">全部投稿</a>
            <a href="/contributions.html?status=0" class="filter-tab {if condition='isset($status) && $status eq "0"'}active{/if}">待审核</a>
            <a href="/contributions.html?status=1" class="filter-tab {if condition='isset($status) && $status eq "1"'}active{/if}">已通过</a>
            <a href="/contributions.html?status=2" class="filter-tab {if condition='isset($status) && $status eq "2"'}active{/if}">已拒绝</a>
        </div>
        <a href="/contribute.html" class="btn btn-primary">
            <i class="bi bi-plus-lg"></i> 新建投稿
        </a>
    </div>

    <div id="contributionList">
        {carefree:contribution limit='10' status='status' userid='current_user_id' orderby='create_time' id='contrib' empty='<div class="empty-state"><i class="bi bi-inbox"></i><h5>暂无投稿</h5><p class="text-muted">您还没有提交任何投稿</p><a href="/contribute.html" class="btn btn-primary mt-3"><i class="bi bi-plus-lg"></i> 立即投稿</a></div>'}
        <div class="contribution-card">
            <div class="contribution-header">
                <div style="flex: 1;">
                    <h3 class="contribution-title">{$contrib.title}</h3>
                    <div class="contribution-meta">
                        <span><i class="bi bi-calendar"></i> {$contrib.time_ago ?: $contrib.create_time}</span>
                        <span><i class="bi bi-person"></i> {$contrib.author_nickname ?: '匿名'}</span>
                    </div>
                </div>
                <span class="contribution-status status-{if condition='$contrib.status eq 0'}pending{elseif condition='$contrib.status eq 1'}approved{else /}rejected{/if}">
                    {$contrib.status_text}
                </span>
            </div>
            <div class="contribution-content">
                {$contrib.content_preview}
            </div>
            {if condition="$contrib.reason"}
            <div class="alert alert-warning mb-3">
                <i class="bi bi-exclamation-triangle"></i>
                <strong>审核意见：</strong>{$contrib.reason}
            </div>
            {/if}
            <div class="contribution-actions">
                {if condition="$contrib.status eq 1 && $contrib.article_id"}
                <a href="/article/{$contrib.article_id}.html" class="btn btn-sm btn-outline-primary">
                    <i class="bi bi-eye"></i> 查看文章
                </a>
                {/if}
                {if condition="$contrib.status eq 0"}
                <a href="/contribute.html?id={$contrib.id}" class="btn btn-sm btn-outline-primary">
                    <i class="bi bi-pencil"></i> 编辑
                </a>
                {/if}
                <button class="btn btn-sm btn-outline-danger" onclick="deleteContribution({$contrib.id})">
                    <i class="bi bi-trash"></i> 删除
                </button>
            </div>
        </div>
        {/carefree:contribution}
    </div>

    <!-- 分页 -->
    {if condition="isset($last_page) && $last_page > 1"}
    <nav class="mt-4">
        {carefree:pagelist total='$total' pagesize='$pagesize' currentpage='$current_page' url='/contributions.html?page=[PAGE]' style='full' /}
    </nav>
    {/if}
</div>
{/block}

{block name="script"}
<script src="/assets/js/contributions.js"></script>
{/block}
